﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using ITS.Core.Domain.Contents;

namespace ITS.Website.Models
{
    public class ContentItemModel
    {
        public Int64 ContentID { get; set; }
        public DateTime CreatedDate { get; set; }
        public DateTime ModifiedDate { get; set; }
        public bool Active { get; set; }

        public IList<string> Titles
        {
            get
            {
                return _titles ?? (_titles = new List<string>());
            }
            set { _titles = value; }
        }

        public static ContentItemModel FromContentItem(ContentItem contentItem)
        {
            ContentItemModel model = new ContentItemModel()
            {
                ContentID = contentItem.ContentID,
                CreatedDate = contentItem.CreatedDate,
                ModifiedDate = contentItem.ModifiedDate,
                Active = contentItem.Active
            };

            foreach (var desc in contentItem.ContentItemDescriptions)
            {
                model.Titles.Add(desc.Title);
            }

            return model;
        }

        //private
        private IList<string> _titles { get; set; }
    }
}